﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Box2D.XNA;
using Microsoft.Xna.Framework;
using ElementumForever.Utility;
using Microsoft.Xna.Framework.Input;
using ElementumForever.Factory;

namespace ElementumForever
{
    class TestScene : BaseScene
    {
       // private PhysicalWorld world;

        public TestScene(MainGame game)
            : base(game)
        {

            Vector2 gravity = new Vector2(0, -9.8f);
            bool doSleep = false;
            world = new PhysicalWorld(gravity, doSleep);
            this.RegistUpdateHandler(world);

            //RectangleShape rectangle, rectanglWall;

            //rectangle = new RectangleShape();
            //rectangle.OnCreat();
            //rectangle.SetSize(50, 50);
            //rectangle.Origin = new Vector2(rectangle.Width / 2, rectangle.Height / 2);
            //AttachChild(rectangle);

            //rectanglWall = new RectangleShape();
            //rectanglWall.OnCreat();
            //rectanglWall.SetSize(800, 20);
            //rectanglWall.Origin = new Vector2(rectanglWall.Width / 2, rectanglWall.Height / 2);
            //AttachChild(rectanglWall);


            //Body body;
            //body = PhysicalFactory.CreatBody(world, BodyType.Dynamic, rectangle, 1);
            //body.GetFixtureList().SetRestitution(.5f);
            //_body = body;

            //PhysicalConnector physicalConnector = new PhysicalConnector(rectangle, body);
            //world.PhysicalConnectorManager.Add(physicalConnector);

            //body.SetTransform(CoordinateHelper.FromSceneToPhysicalWorld(new Vector2(400, 0)), 0);

            //body = PhysicalFactory.CreatBody(world, BodyType.Static, rectanglWall, 1);

            //physicalConnector = new PhysicalConnector(rectanglWall, body);
            //world.PhysicalConnectorManager.Add(physicalConnector);

            //body.SetTransform(CoordinateHelper.FromSceneToPhysicalWorld(new Vector2(400, 400)), UnitHelper.ToRadians(5));

            //game.input.handleInputEvent += OnHandleInput;

        }

        //Body _body;

        //public bool OnHandleInput(Keys keyId,EButtonState state)
        //{
        //    if (keyId == Keys.Left && state == EButtonState.down)
        //        _body.SetLinearVelocity(new Vector2(-2,_body.GetLinearVelocity().Y));
        //    if (keyId == Keys.Right && state == EButtonState.down)
        //        _body.SetLinearVelocity(new Vector2(2, _body.GetLinearVelocity().Y));

        //    if (keyId == Keys.Left && state == EButtonState.up)
        //        _body.SetLinearVelocity(new Vector2(0, _body.GetLinearVelocity().Y));
        //    if (keyId == Keys.Right && state == EButtonState.up)
        //        _body.SetLinearVelocity(new Vector2(0, _body.GetLinearVelocity().Y));

        //    if (keyId == Keys.Up && state == EButtonState.down)
        //        _body.SetLinearVelocity(new Vector2(_body.GetLinearVelocity().X, 5));
        //    if (keyId == Keys.Up && state == EButtonState.up)
        //        _body.SetLinearVelocity(new Vector2(_body.GetLinearVelocity().X, 0));

        //    //handleInputEvent(keyId, state);
        //    return false;
        //}


        public override void OnUpdate(GameTime gameTime)
        {
            base.OnUpdate(gameTime);
            //Console.WriteLine("body"+body.GetPosition());
            //Console.WriteLine("dt" +gameTime.ElapsedGameTime.Milliseconds);
        }
    }
}
